import 'package:blind_traveler/modules/author/author.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';

import 'home.dart';
import 'tabs/widgets/home_widgets.dart';
import '../../shared/shared.dart';
import '../../widgets/widgets.dart';

class EditInformation extends GetView<HomeLogic> {
  final AuthorLogic c = Get.find();

  EditInformation({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(children: [
      const Background(imageURL: AssetsURL.backgroundPicture2, opacity: 0.59),
      _body()
    ]);
  }

  SafeArea _body() {
    return SafeArea(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Column(children: [
          const AuthorBack(showText: true, text: '关于我'),
          CommonWidget.rowHeight(height: 15),
          CommonWidget.line(opacity: 0.60,thickness: 1),
          CommonWidget.rowHeight(height: 15),
          _buildRow('头像照片'),
          _buildEdit()
        ]),
      ),
    );
  }

  Expanded _buildEdit() {
    return Expanded(
      child: SingleChildScrollView(
        child: Column(
          children: [
            Obx(() => _editHead()),
            _buildRow('关于我'),
            CommonWidget.rowHeight(height: 15),
            EditWidget(
                title: '个性签名', text: controller.state.me.value.signature),
            EditWidget(title: 'ID        ', text: controller.state.me.value.userName),
            EditWidget(
                title: '性别    ', text: c.state.gender.value == 1 ? '男生' : '女生',showGender: true),
            EditWidget(title: '年龄    ', text: controller.state.me.value.age),
            EditWidget(title: '位置    ', text: controller.state.me.value.position),
            _buildTags(),
          ],
        ),
      ),
    );
  }

  Container _buildTags() {
    return Container(
      width: 300,
      margin: const EdgeInsets.all(20),
      decoration: BoxDecoration(
          border: Border.all(color: ColorConstants.themeColor.withOpacity(0.60), width: 1)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _myTags(),
          Obx(
            () => Container(
              margin: const EdgeInsets.all(10),
              child: GridView.builder(
                shrinkWrap: true,
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 4,
                  childAspectRatio: 2.74,
                  mainAxisSpacing: 10,
                  crossAxisSpacing: 10,
                ),
                itemCount: controller.state.me.value.tags.length,
                itemBuilder: (BuildContext context, int index) => Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: ColorConstants.themeColor.withOpacity(0.80),
                    borderRadius: const BorderRadius.all(Radius.circular(20)),
                  ),
                  child: Text(
                    controller.state.me.value.tags[index],
                    style: const TextStyle(
                        color: ColorConstants.tagsColor,
                        fontSize: 11,
                        fontWeight: FontWeight.bold),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Stack _editHead() {
    return Stack(alignment: Alignment.bottomCenter, children: [
      MeAvatar(avatarURL: controller.state.me.value.headURL),
      Positioned(
          bottom: 20,
          child: Container(
              height: 37,
              width: 139,
              decoration: BoxDecoration(color: Colors.white.withOpacity(0.41)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  IconFont(IconNames.edit),
                  const Text('编辑',
                      style: TextStyle(color: ColorConstants.themeColor))
                ],
              )))
    ]);
  }

  Row _buildRow(String text) {
    return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          buildLine(),
          Text(text,
              style: const TextStyle(
                  color: ColorConstants.themeColor, fontSize: 10)),
          buildLine()
        ]);
  }

  Container buildLine() {
    return Container(
        width: 120,
        height: 1,
        color: ColorConstants.themeColor.withOpacity(0.60),
        margin: const EdgeInsets.symmetric(horizontal: 20));
  }

  Container _myTags() {
    return Container(
      margin: const EdgeInsets.all(10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          const Text('MY TAGS:',
              style: TextStyle(color: ColorConstants.themeColor, fontSize: 18)),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              IconFont(IconNames.edit),
              const Text('编辑',
                  style: TextStyle(color: ColorConstants.themeColor))
            ],
          )
        ],
      ),
    );
  }
}
